package pl.edu.utp.calculations;

import pl.edu.utp.ga.Individual;
import pl.edu.utp.ga.Population;
import pl.edu.utp.ga.interfaces.Calculation;

public class PopulationRate {
	
	private Population population;
	
	public PopulationRate(Population population){
		this.population = population;
	}
	
	public double rate(Calculation calculation){
		
		double bestRate = Double.MAX_VALUE;
		for(Individual individual: population.getIndividuals()){
			double individualRate = getIndividualRate(individual, calculation);
			if(individualRate < bestRate){
				bestRate = individualRate;
			}
		}
		return bestRate;
	}
	
	private double getIndividualRate(Individual individual, Calculation calculation){
		individual.rate(calculation);
		return individual.getRate();
	}
}
